<template>
  <view class="mine-container" :style="{height: `${windowHeight}px`}">
    <!--顶部个人信息栏-->
    <view class="header-section">
      <view class="flex padding justify-between">
        <view class="flex align-center">
          <view v-if="!avatar" class="cu-avatar xl round bg-white">
            <view class="iconfont text-gray icon" style="font-size:120rpx;">&#xe634;</view>
          </view>
          <image v-if="avatar" @click="handleToAvatar" :src="FormData.avatar" class="cu-avatar xl round" mode="widthFix">
          </image>
          <view v-if="!name" @click="handleToLogin" class="login-tip">
            点击登录
          </view>
          <view v-if="name"  @click="handleToInfo" class="user-info">
            <view class="u_title">
            {{FormData.userName}}
            </view>
          </view>
        </view>
        <view @click="handleToInfo" class="flex align-center">
          <text>个人信息</text>
          <view class="iconfont icon-right">&#xe60d;</view>
        </view>
      </view>
    </view>
    <view class="content-section">
      <view class="mine-actions grid col-4 text-center">
        <view class="action-item">
          <view style="font-size: 17px;">￥{{FormData.accountValue}}</view>
          <text class="text">余额</text>
        </view>
        <view class="action-item" @click="handleAdress">
          <view class="iconfont icon">&#xe63d;</view>
          <text class="text">地址管理</text>
        </view>
        <view class="action-item" @click="handleBuilding">
          <view class="iconfont icon">&#xe64e;</view>
          <text class="text">会员中心</text>
        </view>
      </view>

      <view class="menu-list">
        <view class="list-cell list-cell-arrow" @click="handleToEditInfo">
          <view class="menu-item-box">
            <view>余额充值</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow" @click="notice">
          <view class="menu-item-box">
            <view>公告中心</view>
          </view>
        </view>
		<view class="list-cell list-cell-arrow">
		  <view class="menu-item-box">
		    <view>客服中心</view>
		  </view>
		</view>
		<view class="list-cell list-cell-arrow">
		  <view class="menu-item-box" @click="userEvaluation">
		    <view>用户评价</view>
		  </view>
		</view>
        <view class="list-cell list-cell-arrow" @click="handleAbout">
          <view class="menu-item-box">
            <view>投诉建议</view>
          </view>
        </view>
        <view class="list-cell list-cell-arrow">
          <view class="menu-item-box">
            <view>关于我们</view>
          </view>
        </view>
		<view class="list-cell list-cell-arrow">
		  <view class="menu-item-box" @click="handleLogout">
		    <view @click="handleLogout">退出登录</view>
		  </view>
		</view>
      </view>

    </view>
  </view>
</template>

<script>
  import storage from '@/utils/storage'
  import {logout,getInfo} from '@/api/login.js';
  export default {
    data() {
      return {
		  avatar:'this.FormData.avatar',
		  name:'this.FormData.userName',
		FormData:{
		}
      }
    },
	created(){
		getInfo().then(res=>{
			if(res.code==200){
				this.FormData=res.data.user;
				console.log(this.FormData);
			}
		})	
	},
    computed: {
      windowHeight() {
        return uni.getSystemInfoSync().windowHeight - 50
      }
    },
    methods: {
      handleToInfo() {
        this.$tab.navigateTo('/pages/mine/info/index')
      },
      handleToEditInfo() {
        this.$tab.navigateTo('/pages/mine/info/edit')
      },
	  notice(){
		 uni.navigateTo({
		 	url:'/pages/mine/about/notice'
		 }) 
	  },
      handleToLogin() {
        this.$tab.navigateTo('/pages/login');
      },
      handleToAvatar() {
        this.$tab.navigateTo('/pages/mine/avatar/index')
      },
	  userEvaluation(){
		  uni.navigateTo({
		  	url:'/pages/mine/about/userEvaluation'
		  })
	  },
      handleLogout() {
        this.$modal.confirm('确定要退出登录吗？').then(() => {
			logout().then(res=>{
			console.log(res);
				if(res.code==200){
					uni.removeStorageSync('localtoken');
					uni.removeStorageSync('avatar');
					uni.removeStorageSync('name');
					this.$tab.reLaunch('/pages/login')
				}else{
					this.$modal.alert('退出登录失败');  
				}
			})
        })
      },
      handleAdress() {
        this.$tab.navigateTo('/pages/mine/adress/adress')
      },
      handleAbout() {
        this.$tab.navigateTo('/pages/mine/about/index')
      },
      handleBuilding() {
        this.$modal.showToast('暂未开通')
      }
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #f5f6f7;
  }

  .mine-container {
    width: 100%;
    height: 100%;


    .header-section {
      padding: 15px 15px 40px 15px;
      background-color:#E99D42;
      color: #6C6C6C;

      .login-tip {
        font-size: 18px;
        margin-left: 10px;
      }

      .cu-avatar {
        border: 2px solid #eaeaea;

        .icon {
          font-size: 50px;
        }
      }

      .user-info {
        margin-left: 15px;

        .u_title {
          font-size: 18px;
          line-height: 30px;
        }
      }
    }

    .content-section {
      position: relative;
      top: -50px;
      .mine-actions {
        margin: 10px 15px;  
        padding: 15px 0px;
        border-radius: 8px;
        background-color: white;
		margin-bottom: -5px;
        .action-item {
			margin-left:15px;
          .icon {
            font-size: 24px;
          }

          .text {
            display: block;
            font-size: 13px;
            margin: 8px 0px;
          }
        }
      }
    }
  }
</style>
